/**
 * @author ${baseInfo.user!''}
   @time   ${baseInfo.date!''}
 */
package ${baseInfo.basePackage!''}.service.${baseInfo.moduleName!''};

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ct.common.dto.PageDto;
import ${baseInfo.basePackage!''}.dao.${baseInfo.moduleName!''}.${baseInfo.className!''}Dao;
import ${wholeClassName!''};
import org.springframework.transaction.annotation.Transactional;
import com.ct.common.util.ListUtil;

@Service("${baseInfo.objectName!''}Service")
public class ${baseInfo.className!''}Service {

	private static Logger logger = LoggerFactory.getLogger(${baseInfo.className!''}Service.class);

	@Autowired
	private ${baseInfo.className!''}Dao ${baseInfo.objectName!''}Dao;
	
	public int update(${baseInfo.className!''} ${baseInfo.objectName!''}) throws Exception{
		return this.${baseInfo.objectName!''}Dao.update(${baseInfo.objectName!''});
	}
	
	public int updateById(${baseInfo.className!''} ${baseInfo.objectName!''}) throws Exception{
		return this.${baseInfo.objectName!''}Dao.updateById(${baseInfo.objectName!''});
	}
	
	public int save(${baseInfo.className!''} ${baseInfo.objectName!''}) {
		return this.${baseInfo.objectName!''}Dao.save(${baseInfo.objectName!''});
	}
	
	public ${baseInfo.className!''} getById(Serializable id) {
		return this.${baseInfo.objectName!''}Dao.getById(id);
	}
	
	public List<${baseInfo.className!''}> selectList(${baseInfo.className!''} ${baseInfo.objectName!''}) {
		return this.${baseInfo.objectName!''}Dao.selectList(${baseInfo.objectName!''});
	}
	
	public ${baseInfo.className!''} selectOne(${baseInfo.className!''} ${baseInfo.objectName!''}) {
		return this.${baseInfo.objectName!''}Dao.selectOne(${baseInfo.objectName!''});
	}
	
	public int count(${baseInfo.className!''} ${baseInfo.objectName!''}) {
		return this.${baseInfo.objectName!''}Dao.count(${baseInfo.objectName!''});
	}
	
	public int delete(${baseInfo.className!''} ${baseInfo.objectName!''}){
		return this.${baseInfo.objectName!''}Dao.deleteByProperty(${baseInfo.objectName!''});
	}

	public PageDto selectByPage(PageDto page, Map<String, Object> paramsMap) {
		return this.${baseInfo.objectName!''}Dao.selectByPage(page.getCurrentPage() == null ? 1 : page.getCurrentPage(), page.getPageSize() == null ? 10 : page.getPageSize(), paramsMap);
	}
	
	public List<${baseInfo.className!''}> selectPageAll(Map<String, Object> paramsMap) {
		return this.${baseInfo.objectName!''}Dao.selectPageAll(paramsMap);
	}
	
	@Transactional(rollbackFor=Exception.class)
	public int deleteIds(String ids) {
		List<Long> listIds = new ArrayList<Long>();
		if(StringUtils.isNotBlank(ids)){
			String[] idArray = ids.split(",");
			for(String id : idArray){
				
				if(StringUtils.isNotBlank(id)){
					listIds.add(Long.valueOf(id));
				}
			}
		}
		
		if(ListUtil.isNotEmpty(listIds)){
			return this.${baseInfo.objectName!''}Dao.deleteIds(listIds);
		}else{
			return 0;
		}
	}
}